<?php
/*
Template Name: Projects Template
*/
?>

<?php get_header(); ?>

<?php the_post(); 

	/*
$args = array(
		'type' => 'post',
		'orderby' => 'id',
		'order' => 'ASC',
		'taxonomy' => 'portfolio',
		'pad_counts' => false );
	
	$categories = get_categories( $args );
	
	print_r($categories);
*/
  //$projects_list = new WP_Query( 'orderby=post_date&order=DESC&post_type=portfolio&post_status=publish&portfolio_category=cat' );
 /*
 $projects_list = get_posts( array( 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'portfolio', 'post_status' => 'publish', 'portfolio_category' => 'Cat' ) );
  print_r($projects_list);

*/

$querystr = "
	SELECT term_id
	FROM $wpdb->term_taxonomy
	WHERE taxonomy = 'du-an'
";

$categories = $wpdb->get_results($querystr, OBJECT);

$catid = 0;

if (!isset($_GET['cat_id'])){
	$catid = $categories[0]->term_id;
} else {
	$catid = $_GET['cat_id'];
}

$cat_effect = get_option("portfolio_transition_effect_$catid");

//echo "catid: ".$catid;


$querystr = "
	SELECT term_taxonomy_id
	FROM $wpdb->term_taxonomy
	WHERE term_id = ".$catid."
";

$pageposts = $wpdb->get_results($querystr, OBJECT);
$term_taxonomy_id = $pageposts[0]->term_taxonomy_id;


$querystr = "
	SELECT object_id
	FROM $wpdb->term_relationships
	WHERE term_taxonomy_id = ".$term_taxonomy_id."
";
$pageposts = $wpdb->get_results($querystr, OBJECT);


$posts = array();
foreach ($pageposts as $pp){
	$id = $pp->object_id;
	$querystr = "
		SELECT $wpdb->posts.* 
		FROM $wpdb->posts
		WHERE $wpdb->posts.ID = $id 
		AND $wpdb->posts.post_status = 'publish'
		ORDER BY $wpdb->posts.post_date DESC
	";
	$result = $wpdb->get_results($querystr, OBJECT);
	array_push($posts, $result);
}

?>

<!-- start Content Home -->				
<div class="content">

<div class="titlepage">
	<p><span><?php the_title(); ?></span></p>
</div>

<div id="projects">

	<!-- Thumbnails projects section -->
	<div class="gallery_projects">
		
		<div id="content_proj" class="content_proj">
			<div class="projectnav">							
				<a href="javascript:;" class="nobackthumbs" ></a>
				<a href="javascript:;" class="project_0 moreinfo"></a>

				<ul class="linkseffects">
					<?php $cat_total = 1; foreach ($categories as $cat) : ?>
					<?php 
						$querystr2 = "
							SELECT term_id, name
							FROM $wpdb->terms
							WHERE term_id = ".$cat->term_id."
						";
						
						$categ = $wpdb->get_results($querystr2, OBJECT);

					?>
					<li><a href="<?php $questionmark = strpos($_SERVER["REQUEST_URI"],"?"); $amper = strpos($_SERVER["REQUEST_URI"],"&"); if ($questionmark && $amper){ $url = substr($_SERVER["REQUEST_URI"], 0, $amper); $url .= '&cat_id=' . $categ[0]->term_id; } if ($questionmark && !$amper){$url = $_SERVER["REQUEST_URI"]. '&cat_id=' . $categ[0]->term_id; } if (!$questionmark){ $url = $_SERVER["REQUEST_URI"]. '&cat_id=' . $categ[0]->term_id; } echo $url;?>" class="leffect <?php if(!empty($_GET['cat_id']) && $_GET['cat_id'] == $categ[0]->term_id) echo 'selected'; else if(empty($_GET['cat_id']) && $cat_total == 1) echo 'selected'; ?>"><?php echo $categ[0]->name; ?></a></li>
					<?php $cat_total++; ?>
					<?php endforeach; ?>
				</ul>

				<span id="css_prev" class="css_prev_nav"></span>					
				<span id="css_next" class="css_next_nav"></span>
			</div>
			<div class="typedividerpr"></div>
			<div class="projects">
				<ul class="tj_gallery">
					<?php $project_total = 1; foreach ($posts as $pl) : ?>
						<?php
							$cust_project_thumb_id = array();
							$cust_project_thumb = '';
                            
                            if(has_post_thumbnail( $pl[0]->ID ))
                            {
                                $cust_project_thumb_id = wp_get_attachment_image_src( get_post_thumbnail_id( $pl[0]->ID ), array(175,167) );
                            }
                            if(!empty($cust_project_thumb_id))
                            {
                                $cust_project_thumb = $cust_project_thumb_id[0];
                            }else
                            {
                                $cust_project_thumb = bloginfo('template_directory') . '/img/no-thumb.png';
                            }
						?>
						<li id="project_<?php echo $project_total; ?>">
                            <a href="<?php echo the_permalink(); ?>">
                                <img src="<?php echo $cust_project_thumb; ?>" width="175" height="167"><span class="descript"/><?php if (strlen($pl[0]->post_title) > 14) { $desc = substr($pl[0]->post_title, 0, 14)."..."; } else {$desc = $pl[0]->post_title;} echo $desc; ?></span></a></li>
					<?php $project_total++; ?>
					<?php endforeach; ?>
				
				</ul>
			</div>
			<div class="typedividerprbottom"></div>					
		</div>
	</div>
	<!-- END Thumbnails projects section -->
	
	<div id="projectmoreinfo" style="display:none;">
	<!-- MoreInfo projects section -->

	<div class="typedividerpr"></div>
	<div class="openproject">
<div class="typedividerprbottom"></div>
</div>
	
	

	

</div>

		<div class="hidecorner"></div>
		
		</div>	
	</div>	
</div>





		
			<?php 
			global $post, $wp_query;
			$args = array(
				'post_type'					=> 'gallery',
				'post_status'				=> 'publish',
				'name'							=> $wp_query->query_vars['name'],
				'posts_per_page'		=> 1
			);	
			$second_query = new WP_Query( $args ); 
			$gllr_options = get_option( 'gllr_options' );
			if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post(); ?>
				<h1 class="home_page_title"><?php the_title(); ?></h1>
					<?php the_content(); 
					$posts = get_posts(array(
						"showposts"			=> -1,
						"what_to_show"	=> "posts",
						"post_status"		=> "inherit",
						"post_type"			=> "attachment",
						"orderby"				=> $gllr_options['order_by'],
						"order"					=> $gllr_options['order'],
						"post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
						"post_parent"		=> $post->ID
					));
					if( count( $posts ) > 0 ) {
						$count_image_block = 0;
						foreach( $posts as $attachment ) { 
							$key = "gllr_image_text";
							$link_key = "gllr_link_url";
							$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'photo-thumb' );
							$image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
							$image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
						}
                    } 
				endwhile; else:
                ?>
				<div class="gallery_box_single">
					<p class="not_found"><?php _e('Sorry - nothing to found.', 'gallery'); ?></p>
				</div>
				<?php endif; ?>
























<?php get_footer(); ?>